package com.hgk.common.common.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.widget.Button;
import android.widget.RelativeLayout;

/**
 * Created by sam on 15/8/6.
 */
public class BaseFragmentActivity extends BallTitleAcitivty {
    protected FragmentManager mFragmentManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mFragmentManager = getSupportFragmentManager();
    }

    @Override
    public void setLeftButton(RelativeLayout relativeLayout,Button button) {

    }

    @Override
    public void setRightButton(RelativeLayout relativeLayout,Button button) {

    }

    @Override
    public Object getTitleString() {
        return null;
    }

    @Override
    public int getBodyView() {
        return 0;
    }
    public void replace(int resid, Fragment fragment) {
        if(fragment!=null) {
            mFragmentManager.beginTransaction().replace(resid, fragment).commitAllowingStateLoss();
        }
    }

    /**
     * @param resid
     * @param fragment
     */
    public void add(int resid, Fragment fragment) {
        if(fragment!=null) {
            mFragmentManager.beginTransaction().add(resid, fragment).commitAllowingStateLoss();
        }
    }
   public void remove(Fragment fragment){
       if(fragment!=null) {
           mFragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss();
       }
   }
    /**
     * 显示fragment
     *
     * @param fragment
     */
    public void show(Fragment fragment) {
        if(fragment!=null) {
            mFragmentManager.beginTransaction().show(fragment).commitAllowingStateLoss();
        }
    }

    /**
     * 隐藏fragment
     *
     * @param fragment
     */
    public void hide(Fragment fragment) {
        if(fragment!=null) {
            mFragmentManager.beginTransaction().hide(fragment).commitAllowingStateLoss();
        }
    }
}
